import rxAjax from '@/assets/js/ajax.js';

//表单权限配置 api接口
export const LoginApi = {};

LoginApi.authUrl= '/api-uaa';
LoginApi.userUrl= '/api-user';
LoginApi.systemUrl= '/api-system';

//注册微信公众号用户比登录
LoginApi.addWxGzhUserAndLogin= function(parameter) {
    return rxAjax.postJson(LoginApi.authUrl+'/oauth/user/addWxGzhUserAndLogin',parameter);
}

//获取手机验证码(注册用户)
LoginApi.getNewUserSmsCaptcha = ({mobile}) => rxAjax.get(
    LoginApi.authUrl+'/validata/smsCodeFromNewUser/'+mobile
)

//获取手机验证码
LoginApi.getSmsCaptcha = ({mobile}) => rxAjax.get(
    LoginApi.authUrl+'/validata/smsCode/'+mobile
)

//轮询微信公众是否扫码
LoginApi.getTokenByTicket = (params) => rxAjax.get(
    LoginApi.authUrl+"/oauth/user/getTokenByTicket?tenantId="+params.tenantId+"&ticket="+params.ticket+"&sceneId="+params.sceneId+"&hostName="+params.hostName
)

//跳转
LoginApi.authorize = (code) => rxAjax.get(
  LoginApi.authUrl + '/oauth/user/authorize?code='+code,
)

/**
 * 获取验证码
 */
LoginApi.getValidCodeConfig = () => rxAjax.get(LoginApi.authUrl + '/validata/getValidCodeConfig')

/**
 * 获取获取多语言列表
 */
LoginApi.getLoginConfig = function (hostName) {
    console.info("LoginApi.getLoginConfig");
    return rxAjax.get(LoginApi.systemUrl + '/system/core/public/getLoginConfig?hostName='+hostName);
}

//登录
LoginApi.login = (parameter) => rxAjax.postForm(
   LoginApi.authUrl + '/oauth/user/token',
   parameter,{token:false}
)
//登录(手机号)
LoginApi.loginByMobile = (parameter) => rxAjax.postUrl(
  LoginApi.authUrl + '/oauth/user/mobile/token',
  parameter
)

//获取验证码
LoginApi.imgcode = (uuid) => rxAjax.getBlob(
  LoginApi.authUrl+'/validata/code/'+uuid
)

//获取手机验证码
LoginApi.getSmsCaptcha = ({mobile}) => rxAjax.get(
  LoginApi.authUrl+'/validata/smsCode/'+mobile
)

//获取用户信息
LoginApi.getUserInfo = (uuid) => rxAjax.get(
  LoginApi.userUrl+'/user/org/osUser/current'
)

//获取用户信息与菜单
LoginApi.getLoginUserAndMenu = (uuid) => rxAjax.get(
  LoginApi.userUrl+'/user/org/osUser/getLoginUserAndMenu'
)
//获取钉钉扫码登录地址
LoginApi.getDdQRCodeUrl=(params)=>rxAjax.postUrl(
  LoginApi.userUrl+'/dd/getQRCodeUrl',params
)

//通过Code获取钉钉用户ID
LoginApi.getDdIdQRCode=(params)=>rxAjax.postUrl(
  LoginApi.userUrl+'/dd/getDdIdQRCode',params
)

//根据钉钉用户ID自动登录  Elwin ZHANG
LoginApi.autoLoginByDdId=(params)=>rxAjax.postUrl(
  LoginApi.authUrl+'/oauth/logindd',params
)

//获取企业微信扫码登录地址
LoginApi.getWxEntQRCodeUrl=(params)=>rxAjax.postUrl(
  LoginApi.userUrl+'/wxent/getQRCodeUrl',params
)
//通过Code获取企业微信用户ID
LoginApi.getOpenIdByCode=(params)=>rxAjax.postUrl(
  LoginApi.userUrl+'/wxent/getOpenIdByCode',params
)
//根据微信OpenId自动登录 Elwin ZHANG
LoginApi.autoLoginByWxId=(params)=>rxAjax.postUrl(
  LoginApi.authUrl+'/oauth/loginwx',params
)

//退出登录
LoginApi.logout = (token) => rxAjax.postUrl(
  LoginApi.authUrl+'/oauth/remove/token',
  {"token": token}
)


//用户首次登录修改密码
LoginApi.changePassword = (parameter) => rxAjax.postForm(
    LoginApi.userUrl + '/user/org/osUser/changePassword',
    parameter
)

//cas验证ticket并免密登录
LoginApi.loginByTicket = (parameter) => rxAjax.postForm(
    LoginApi.authUrl + '/oauth/user/loginByTicket',
    parameter,{token:false}
)

//获取第三方平台授权地址参数tenantId,loginType,redirectUrl, state
LoginApi.getAuthUrl = (params) => rxAjax.get(
    LoginApi.authUrl+"/oauth/user/authUrl?tenantId="+params.tenantId+"&loginType="+params.loginType+"&redirectUrl="+params.redirectUrl+"&state="+params.state
)
//根据微信code自动登录code,tenantId,loginType
LoginApi.autoLoginByCode=(params)=>rxAjax.postUrl(
    LoginApi.authUrl+'/oauth/user/autoLogin',params
)

export  default LoginApi;
